import click
import subprocess
import os


@click.command()
@click.option("--dir", type=str)
def run(dir):

    file_dir = dir + "/elf/"
    for filename in os.listdir(file_dir):
        if ".so" in filename:
            print("Processing {} ...".format(filename))
            proc = subprocess.Popen('ida64.exe -A -c ' + '-S\"/Users/mhli/workspace/tvm-reversion/idapro/test.py /"' +
                                    '{}/{}'.format(file_dir, filename),
                                    shell=True)
            proc.wait()
        if os.path.exists("{}/{}.i64".format(file_dir, filename)):
            os.remove("{}/{}.i64".format(file_dir, filename))


if __name__ == "__main__":
    run()
